public class Tilecoder {
	final static double RANGE_V = .14;
	final static double RANGE_X = 1.7;
	final static double MIN_V = -.07;
	final static double MIN_X = -1.2;
	static int numOfTilings = 4;
	static int X_GRID_SPACES = 8;
	static int V_GRID_SPACES = 8;
	static double OFFSET_X = (RANGE_X/X_GRID_SPACES)/numOfTilings;
	static double OFFSET_V = (RANGE_V/V_GRID_SPACES)/numOfTilings;
	static int DIFF_BETWEEN_RUNS = (X_GRID_SPACES+1)*(V_GRID_SPACES+1);

	
	public static void tilecode(double x, double v, int[] tilecodeIndices) {
		for(int i=0;i<numOfTilings;i++){
			int horizontal = (int) ((v-MIN_V)/(RANGE_V/V_GRID_SPACES));
			int vertical = (int) ((x-MIN_X)/(RANGE_X/X_GRID_SPACES));
			int tileNumber = horizontal + (V_GRID_SPACES+1)*vertical + i*DIFF_BETWEEN_RUNS;
			tilecodeIndices[i] = tileNumber;
			x += OFFSET_X;
			v += OFFSET_V;
		}
	}
}
